home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SunSoft Catalyst CDWARE 1996 May to August
/
Catalyst CDWARE 1996 May to August.iso
/
.products
/
RogueWave
/
Wave.java
< prev
Wrap
Text File
|
1996-01-31
|
3KB
|
133 lines
/*
* Wave.java -- Modified version of Sun's TumblingDuke example.
*/
import java.io.InputStream;
import java.applet.Applet;
import java.awt.*;
import java.net.*;
/**
* A simple Item class to play an image loop. The "img" tag parameter
* indicates what image loop to play.
*
* @author James Gosling
* @version 1.17, 31 Jan 1995
*/
public
class Wave extends Applet implements Runnable {
/**
* The current loop slot.
*/
int loopslot = 0;
/**
* The directory or URL from which the images are loaded
*/
String dir;
/**
* The thread animating the images.
*/
Thread kicker = null;
/**
* The length of the pause between revs.
*/
int pause;
int offset;
int off;
int speed;
int nimgs;
/**
* The images.
*/
Image imgs[];
int maxWidth;
/**
* Initialize the applet. Get attributes.
*/
public void init() {
String at = getParameter("img");
dir = (at != null) ? at : "images/wave";
at = getParameter("pause");
pause = (at != null) ? Integer.valueOf(at).intValue() : 100;
at = getParameter("speed");
speed = (at != null) ? (1000 / Integer.valueOf(at).intValue()) : 100;
at = getParameter("nimgs");
nimgs = (at != null) ? Integer.valueOf(at).intValue() : 16;
at = getParameter("maxwidth");
maxWidth = (at != null) ? Integer.valueOf(at).intValue() : 0;
}
/**
* Run the image loop. This methods is called by class Thread.
* @see java.lang.Thread
*/
public void run() {
Thread.currentThread().setPriority(Thread.NORM_PRIORITY-1);
imgs = new Image[nimgs];
for (int i = 1; i < nimgs; i++) {
imgs[i] = getImage(getDocumentBase(), dir + "/wave" + i + ".gif");
}
if (nimgs > 1) {
while (kicker != null) {
//System.out.println("frame = " + loopslot);
if (++loopslot >= nimgs) {
loopslot = 0;
}
repaint();
try {
Thread.sleep(speed + ((loopslot == nimgs - 1) ? pause : 0));
} catch (InterruptedException e) {
break;
}
}
}
}
public boolean imageUpdate(Image img, int flags,
int x, int y, int w, int h) {
if ((flags & (SOMEBITS|FRAMEBITS|ALLBITS)) != 0) {
if ((imgs != null) && (loopslot < nimgs) && (imgs[loopslot] == img)) {
repaint(100);
}
}
return (flags & (ALLBITS|ERROR)) == 0;
}
/**
* Paint the current frame.
*/
public void paint(Graphics g) {
//System.out.println("paint");
if ((imgs != null) && (loopslot < nimgs) && (imgs[loopslot] != null)) {
g.drawImage(imgs[loopslot], 0, 0, this);
}
}
/**
* Start the applet by forking an animation thread.
*/
public void start() {
if (kicker == null) {
kicker = new Thread(this);
kicker.start();
}
}
/**
* Stop the applet. The thread will exit because kicker is set to null.
*/
public void stop() {
if (kicker != null) {
kicker.stop();
kicker = null;
}
}
}